package com.jyw.web.controller.system;

import com.jyw.common.annotation.Log;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.enums.BusinessType;
import com.jyw.system.domain.dto.*;
import com.jyw.system.domain.vo.SysOrderAutoDispatchConfigVo;
import com.jyw.system.domain.vo.SysOrderAutoDispatchVo;
import com.jyw.system.service.ISysOrderAutoDispatchConfigService;
import com.jyw.system.service.ISysOrderAutoDispatchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Created by ZhangCheng on 2023/08/16 (系统自动派单配置)
 */
@Api(tags = "系统自动派单配置")
@RestController
@RequestMapping("/system/orderAutoDispatchConfig")
public class SysOrderAutoDispatchConfigController {

    @Resource
    private ISysOrderAutoDispatchConfigService sysAutoOrderConfigService;

    @Resource
    private ISysOrderAutoDispatchService sysOrderAutoDispatchService;

    /**
     * 获取系统自动派单配置
     *
     * @return
     */
    @GetMapping("/getConfig")
    @ApiOperation("获取系统自动派单配置")
    public CommonResult<SysOrderAutoDispatchConfigVo> getConfig() {
        return CommonResult.success(sysAutoOrderConfigService.getDefaultConfig());
    }

    /**
     * 修改系统自动派单配置
     *
     * @param sysAutoOrderConfigVo
     * @return
     */
    @Log(title = "修改系统自动派单配置", businessType = BusinessType.UPDATE)
    @PutMapping("/updateConfig")
    @ApiOperation("修改系统自动派单配置")
    public CommonResult updateConfig(@RequestBody SysOrderAutoDispatchConfigVo sysAutoOrderConfigVo) {
        sysAutoOrderConfigService.updateConfig(sysAutoOrderConfigVo);
        return CommonResult.success();
    }

    /**
     * 查询自动派单故障分类配置
     *
     * @return
     */
    @GetMapping("/getFaultTypeList")
    @ApiOperation("查询自动派单故障分类配置")
    public CommonResult<List<SysOrderAutoDispatchVo>> getFaultTypeList(SysOrderAutoDispatchQueryDto queryDto) {
        List<SysOrderAutoDispatchVo> list=sysOrderAutoDispatchService.queryFaultTypeList(queryDto);
        return CommonResult.success(list);
    }

    /**
     * 查询自动派单报修科室配置
     *
     * @return
     */
    @GetMapping("/getRepairDepartList")
    @ApiOperation("查询自动派单报修科室配置")
    public CommonResult<List<SysOrderAutoDispatchVo>> getRepairDepartList(SysOrderAutoDispatchQueryDto queryDto) {
        List<SysOrderAutoDispatchVo> list=sysOrderAutoDispatchService.queryRepairDepartList(queryDto);
        return CommonResult.success(list);
    }

    /**
     * 新增报修科室故障分类派单
     */
    @Log(title = "报修科室故障分类派单", businessType = BusinessType.INSERT)
    @PostMapping(value = "add")
    @ApiOperation("新增报修科室故障分类派单")
    public CommonResult add(@RequestBody @Valid SysOrderAutoDispatchAddDto addDto) {
        sysOrderAutoDispatchService.add(addDto);
        return CommonResult.success();
    }

    /**
     * 修改报修科室故障分类派单
     */
    @Log(title = "报修科室故障分类派单", businessType = BusinessType.UPDATE)
    @PutMapping(value = "edit")
    @ApiOperation("修改报修科室故障分类派单")
    public CommonResult edit(@RequestBody @Valid SysOrderAutoDispatchEditDto editDto) {
        sysOrderAutoDispatchService.edit(editDto);
        return CommonResult.success();
    }
}
